home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Storage / Bento / SUClone.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  3.4 KB  |  151 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SUClone.cpp
  3.  
  4.     Contains:    Implementation SUCloneHelper class.
  5.  
  6.     Owned by:    Vincent Lo
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>     5/26/95    VL        1251403: Multithreading naming support.
  13.          <2>     5/25/95    jpa        List.h --> LinkList.h [1253324]
  14.          <1>     1/26/95    VL        first checked in
  15.     
  16.     To Do:
  17.     In Progress:
  18.         
  19. */
  20.  
  21. #ifndef _SUCLONE_
  22. #include "SUClone.h"
  23. #endif
  24.  
  25. #ifndef _LINKLIST_
  26. #include "LinkList.h"
  27. #endif
  28.  
  29. #ifndef _ODNEW_
  30. #include "ODNew.h"
  31. #endif
  32.  
  33. //==============================================================================
  34. // Local classes
  35. //==============================================================================
  36.  
  37. class ScopeIDLink : public Link {
  38.  
  39. public:
  40.     
  41.     ScopeIDLink(ODID id) {fID = id;}
  42.     ~ScopeIDLink() {};
  43.     
  44.     ODID GetID() {return fID;};
  45.  
  46. private:
  47.     
  48.     ODID    fID;
  49. };
  50.  
  51. class ScopeIDList
  52. {
  53. public:
  54.  
  55.     ScopeIDList() {fHeap = ODRecoverHeapID(this);}
  56.     
  57.     ~ScopeIDList() {fLinkedList.DeleteAllLinks();}
  58.     
  59.     void Reset() {fLinkedList.DeleteAllLinks();}
  60.     
  61.     void Add(ODID id);
  62.     
  63.     ODBoolean Exists(ODID id);
  64.     
  65. private:
  66.  
  67.     LinkedList fLinkedList;
  68.     ODMemoryHeapID    fHeap;
  69.     
  70.     ODMemoryHeapID    GetHeap() {return fHeap;}
  71. };
  72.  
  73.  
  74. //==============================================================================
  75. // SUCloneHelper
  76. //==============================================================================
  77.  
  78. //------------------------------------------------------------------------------
  79. // SUCloneHelper::SUCloneHelper
  80. //------------------------------------------------------------------------------
  81.  
  82. SUCloneHelper::SUCloneHelper()
  83. {
  84.     fHeap = ODRecoverHeapID(this);
  85.     fScopeIDList = new(GetHeap()) ScopeIDList;
  86. }    
  87.  
  88. //------------------------------------------------------------------------------
  89. // SUCloneHelper::SUCloneHelper
  90. //------------------------------------------------------------------------------
  91.  
  92. SUCloneHelper::~SUCloneHelper()
  93. {
  94.     delete fScopeIDList;
  95. }    
  96.  
  97. //------------------------------------------------------------------------------
  98. // SUCloneHelper::ShouldClone
  99. //------------------------------------------------------------------------------
  100.  
  101. ODBoolean SUCloneHelper::ShouldClone(ODDraftKey key, ODID scopeID)
  102. {
  103.     ODBoolean shouldClone = kODFalse;
  104.     
  105.     if (fKey != key) {
  106.         fScopeIDList->Reset();
  107.         fScopeIDList->Add(scopeID);
  108.         fKey = key;
  109.         shouldClone = kODTrue;
  110.     }
  111.     else if (fScopeIDList->Exists(scopeID) == kODFalse) {
  112.         fScopeIDList->Add(scopeID);
  113.         shouldClone = kODTrue;
  114.     }
  115.     return shouldClone;
  116. }
  117.  
  118. //==============================================================================
  119. // ScopeIDList
  120. //==============================================================================
  121.  
  122. //------------------------------------------------------------------------------
  123. // ScopeIDList::Add
  124. //------------------------------------------------------------------------------
  125.  
  126. void ScopeIDList::Add(ODID id)
  127. {
  128.     ScopeIDLink* link = new(GetHeap()) ScopeIDLink(id);
  129.     fLinkedList.AddFirst(link);
  130. }
  131.  
  132. //------------------------------------------------------------------------------
  133. // ScopeIDList::Exists
  134. //------------------------------------------------------------------------------
  135.  
  136. ODBoolean ScopeIDList::Exists(ODID id)
  137. {
  138.     ODBoolean    exists = kODFalse;
  139.     
  140.     LinkedListIterator    iter(&fLinkedList);
  141.     
  142.     ScopeIDLink* link = (ScopeIDLink*) iter.First();
  143.     while (iter.IsNotComplete() && (exists == kODFalse)) {
  144.         if (link->GetID() == id)
  145.             exists = kODTrue;
  146.         link = (ScopeIDLink*) iter.Next();
  147.     }
  148.  
  149.     return exists;
  150. }
  151.